package com.eric.downloader;

import java.util.ArrayList;
import java.util.List;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class BaiduSERPDownloader extends SimplePageDownloader {

	String queryBaseUrl = "http://www.baidu.com/s?wd=";

	String kw;

	public static void main(String args[]) {

	}

	public BaiduSERPDownloader() {
		super();
	}

	public BaiduSERPDownloader(String kw) {
		this.kw = kw;
	}

	public BaiduSERPDownloader(String kw, MyProxy p) {
		super(p);
		this.kw = kw;
	}

	public String kw() {
		return kw;
	}

	public void queryBase(String queryBaseUrl) {
		this.queryBaseUrl = queryBaseUrl;
	}

	public BaiduSERPDownloader get() {
		querySearchEngine(queryBaseUrl, kw);
		return this;
	}

	public BaiduSERPDownloader get(String kw) {
		querySearchEngine(queryBaseUrl, kw);
		return this;
	}

	public List<String> top10Url() {
		List<String> list = new ArrayList<>();
		this.document();
		Elements elements = this.doc.select("h3:nth-child(1) > a:nth-child(1)");
		for (Element e : elements)
			list.add(realUrl(e.attr("href")));
		return list;
	}

}
